package com.jalarbee.stock.product.business;

import java.io.Serializable;

import javax.persistence.EnumType;
import javax.persistence.Enumerated;

public class Quantity implements Serializable {

    private static final long serialVersionUID = 1L;
    private int count;
    @Enumerated(EnumType.STRING)
    private Unit unit;

    public Quantity(int size, Unit unit) {
        super();
        this.count = size;
        this.unit = unit;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int size) {
        this.count = size;
    }

    public Unit getUnit() {
        return unit;
    }

    public void setUnit(Unit unit) {
        this.unit = unit;
    }

    @Override
    public String toString() {
        return count + unit.getSymbol();
    }

    @Override
    public boolean equals(Object obj) {
        // Not strictly necessary, but often a good optimization
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof Quantity)) {
            return false;
        }
        Quantity q = (Quantity) obj;
        return count == q.count && unit.equals(q.unit);
    }

    @Override
    public int hashCode() {
        int hash = 1;
        hash = hash * 31 + count;
        hash = hash * 31 + (unit == null ? 0 : unit.hashCode());
        return hash;
    }
}
